package com.itita.ww2.data;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;

public class ItemConfig {
	public static boolean isLoaded;
	//
	private static ISFSObject itemList; // 物品列表

	public static final void init(ISFSObject data) {
		itemList = data.getSFSObject("item");
		ChestRuleConfig.init(data);
		isLoaded = true;
	}

	private static final ISFSObject getItemCfg(String itemId) {
		return itemList.getSFSObject(itemId);
	}

	public static final int getItemParam1(String itemId) {
		return getItemCfg(itemId).getInt("param1");
	}

	public static final int getItemParam2(String itemId) {
		return getItemCfg(itemId).getInt("param2");
	}

	public static final boolean isItemUseable(String itemId) {
		return getItemCfg(itemId).getBool("useable");
	}

	public static final boolean isItemCompositable(String itemId) {
		return getItemComTable(itemId) != null;
	}

	public static final int getItemEffParam(String itemId) {
		return getItemCfg(itemId).getInt("eff_param");
	}

	public static final int getItemLv(String itemId) {
		ISFSObject itemCfg = getItemCfg(itemId);
		if (!itemCfg.containsKey("lv")) {
			return 0;
		}
		return itemCfg.getInt("lv");
	}

	public static final String getItemNextId(String itemId) {
		ISFSObject itemCfg = getItemCfg(itemId);
		if (!itemCfg.containsKey("next_id")) {
			return "";
		}
		return itemCfg.getUtfString("next_id");
	}

	public static final ISFSObject getItemComResource(String itemId) {
		ISFSObject itemCfg = getItemCfg(itemId);
		if (!itemCfg.containsKey("com_res")) {
			return SFSObject.newInstance();
		}
		return itemCfg.getSFSObject("com_res");
	}

	public static final ISFSObject getItemComTable(String itemId) {
		ISFSObject itemCfg = getItemCfg(itemId);
		if (!itemCfg.containsKey("com_table")) {
			return null;
		}
		return itemCfg.getSFSObject("com_table");
	}

	public static final ISFSObject getEffValueAsObj(String itemId) {
		ISFSObject itemCfg = getItemCfg(itemId);
		if (!itemCfg.containsKey("eff_value")) {
			return null;
		}
		return itemCfg.getSFSObject("eff_value");
	}

	public static final int getEffValueAsInt(String itemId) {
		ISFSObject itemCfg = getItemCfg(itemId);
		if (!itemCfg.containsKey("eff_value")) {
			return 0;
		}
		return itemCfg.getInt("eff_value");
	}

	public static final String getEffValueAsString(String itemId) {
		ISFSObject itemCfg = getItemCfg(itemId);
		if (!itemCfg.containsKey("eff_value")) {
			return "";
		}
		return itemCfg.getUtfString("eff_value");
	}
}
